package com.zqs.compareface.utils.impl;

import com.zqs.compareface.controller.StreamController;
import org.bytedeco.javacv.FFmpegFrameGrabber;

/**
 * @Program: FaceCompare
 * @Description:
 * @Author: zqs
 * @Create： 2021-08-11-21:14
 */
public class CreateFFmpegFramegrabberUtil {
    /**
     * @Description: 创建拉流
     */

    public static FFmpegFrameGrabber createFFmpegFrameGrabber(){
        String streamURL = StreamController.STREAM_URL;
        FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(streamURL);
        grabber.setImageWidth(640);
        grabber.setImageHeight(480);
        grabber.setFrameRate(30.0);
        grabber.setVideoBitrate(40000);
        try {
            grabber.start();
        } catch (FFmpegFrameGrabber.Exception e) {
            e.printStackTrace();
        }
        return grabber;
    }
    /**
     * @param:  grabber
     * @Description: 关闭拉流
     */
    public static void closeFFmpegFrameGrabber(FFmpegFrameGrabber grabber){
        try {
            grabber.release();
            grabber.stop();
        } catch (FFmpegFrameGrabber.Exception e) {
            e.printStackTrace();
        }
    }
}
